{% extends '_base.html' %}
{% load helpers %}
{% load form_helpers %}

{% block content %}
<h1>{% block title %}{{ obj_type|bettertitle }} Import{% endblock %}</h1>
{% block tabs %}{% endblock %}
<div class="row">
	<div class="col-md-7">
        {% if form.non_field_errors %}
            <div class="panel panel-danger">
                <div class="panel-heading"><strong>Errors</strong></div>
                <div class="panel-body">
                    {{ form.non_field_errors }}
                </div>
            </div>
        {% endif %}
		<form action="" method="post" class="form">
		    {% csrf_token %}
		    {% render_form form %}
            <div class="form-group">
                <div class="col-md-12 text-right">
		            <button type="submit" class="btn btn-primary">Submit</button>
		            {% if return_url %}
                        <a href="{{ return_url }}" class="btn btn-default">Cancel</a>
                    {% endif %}
                </div>
            </div>
		</form>
	</div>
	<div class="col-md-5">
        {% if fields %}
            <h4 class="text-center">CSV Format</h4>
            <table class="table">
                <tr>
                    <th>Field</th>
                    <th>Required</th>
                    <th>Description</th>
                </tr>
                {% for name, field in fields.items %}
                    <tr>
                        <td><code>{{ name }}</code></td>
                        <td>{% if field.required %}<i class="glyphicon glyphicon-ok" title="Required"></i>{% endif %}</td>
                        <td>
                            {{ field.help_text|default:field.label }}
                            {% if field.choices %}
                                <br /><small class="text-muted">Choices: {{ field|example_choices }}</small>
                            {% elif field|widget_type == 'dateinput' %}
                                <br /><small class="text-muted">Format: YYYY-MM-DD</small>
                            {% elif field|widget_type == 'checkboxinput' %}
                                <br /><small class="text-muted">Specify "true" or "false"</small>
                            {% endif %}
                        </td>
                    </tr>
                {% endfor %}
            </table>
        {% endif %}
	</div>
</div>
{% endblock %}
